package com.kgc.est.controller;

import com.kgc.est.dto.ModelDto;
import com.kgc.est.feignService.ModelService;
import com.kgc.est.request.ModelReq;
import com.kgc.est.utils.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/model")
public class ModelController {

    Logger log = LoggerFactory.getLogger(ModelController.class);

    @Autowired
    private ModelService modelService;

    @GetMapping("/search")
    public Result search(ModelReq modelReq){
        log.info("商品搜素的入参：{}",modelReq);

        //判断页码和页大小的值
        if (null == modelReq.getPageIndex()){
            modelReq.setPageIndex(1);
        }
        if (null == modelReq.getPageSize()){
            modelReq.setPageSize(20);
        }

        //调用服务提供者提供的方法，对商品进行搜索
        return modelService.searchModel(modelReq);
    }

    /**
     * 根据商品id，查询商品详情
     * @param id
     * @return
     */
    @GetMapping("/{id}/detail")
    public Result<ModelDto> detail(@PathVariable("id")Long id){

        log.info("服务消费者拿到的商品id：{}",id);
        return modelService.detail(id);
    }
}
